﻿using System;
using System.Collections.Generic;
using System.Linq;
using RentalOfCars.Domain.Entities;
using RentalOfCars.Infrastructure.Entities;
using RentalOfCars.Server.Domain.Database;

namespace RentalOfCars.Server.Application
{
    internal class FakeAccessor : IDbAccessor
    {
        #region IDbAccessor Members

        private List<IPerson> _persons = new List<IPerson>();
        private List<ICar> _cars = new List<ICar>();

        public void Connect()
        {
        }

        public void Disconnect()
        {
        }

        public IEmployee GetEmployee(string login)
        {
            if (login == "main")
            {
                return new Employee(1, "main", "main", "main", "main", "", "", 1, "23-93-F8-68-B9-EF-C8-9D-E1-93-F7-C4-58-B3-E0-84", new EmployeeClass(1, "Manager"), DateTime.Now, DateTime.Now);
            }

            return new Employee(1, "", "", "", "", "", "", 1, "", new EmployeeClass(1, "Manager"), DateTime.Now, DateTime.Now);
        }

        public IList<IClient> GetClients()
        {
            return _persons.OfType<IClient>().ToList();
        }

        public IList<ICar> GetCars()
        {
            return _cars.OfType<ICar>().ToList();
        }

        public IList<IDiscount> GetDiscounts()
        {
            var d1 = new Discount(1, 0);
            var d2 = new Discount(2, 5);
            var d3 = new Discount(3, 10);
            var d4 = new Discount(4, 15);

            return new List<IDiscount> {d1, d2, d3, d4};
        }

        public IClient AddClient(IClient client)
        {
            _persons.Add(client);
            return client;
        }

        public void DeleteClient(int clientId)
        {
            foreach (var person in _persons)
            {
                if (person is IClient)
                {
                    if (((IClient)person).ClientId == clientId)
                    {
                        _persons.Remove(person);
                        return;
                    }
                }
            }
        }

        public ICar AddCar(ICar car)
        {
            _cars.Add(car);
            return car;
        }

        public void DeleteCar(int carId)
        {
            foreach (var car in _cars)
            {
                if (car is ICar)
                {
                    if (((ICar)car).ID == carId)
                    {
                        _cars.Remove(car);
                        return;
                    }
                }
            }
        }

        public IList<IClient> GetRegularClients()
        {
            return _persons.OfType<IClient>().ToList();
        }

        public IList<IClient> GetBestClients()
        {
            return _persons.OfType<IClient>().ToList();
        }

        public IList<IClient> GetFineClients()
        {
            return _persons.OfType<IClient>().ToList();
        }

        public IList<IEmployeeClass> GetEmployeeClasses()
        {
            return new List<IEmployeeClass> { new EmployeeClass(1, "Employee"), new EmployeeClass(2, "Manager") };
        }

        public IEmployee AddEmployee(IEmployee employee)
        {
            _persons.Add(employee);
            return employee;
        }

        public IList<IBrand> GetBrands()
        {
            List<IBrand> l = new List<IBrand>();
            l.Add(new Brand(1,"WTF Horse"));
            l.Add(new Brand(3,"Lexus"));
            return l;
        }

        public IList<IFeature> GetFeatures()
        {
            List<IFeature> l = new List<IFeature>();
            l.Add(new Feature(33, "Max Speed"));
            l.Add(new Feature(34, "Power (in horses)"));
            return l;
        }

        public IList<IEmployee> GetEmployees()
        {
            throw new NotImplementedException();
        }

        public void FireEmployee(IEmployee employee)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}